import { createElement, HTMLAttributes, type FC } from 'react';
import classNames from 'classnames';
import { tableFooterDefaultProps } from './defaultProps';
import type { TableFooterOptions, TableHeaderOptions } from './type';
import TableHeader from './TableHeader';

export interface TableFooterProps
  extends TableFooterOptions,
    TableHeaderOptions,
    HTMLAttributes<HTMLTableSectionElement> {}

const TableFooter: FC<TableFooterProps> = (props) => {
  const { className, children, forwardedRef, ...tableFooterProps } = props;

  return createElement(
    TableHeader,
    { as: 'tfoot', forwardedRef, className: classNames(className), ...tableFooterProps },
    children,
  );
};

TableFooter.displayName = 'TableFooter';
TableFooter.defaultProps = tableFooterDefaultProps;

export default TableFooter;
